/*
 * NuevoPaciente.java
 *
 * Created on 28 de septiembre de 2008, 16:57
 */
package podologia;

import java.awt.Color;
import java.text.DecimalFormat;
import javax.persistence.EntityTransaction;
import javax.swing.JOptionPane;
import javax.swing.text.JTextComponent;
import podologia.beansDB.Barrio;
import podologia.beansDB.Direccion;
import podologia.beansDB.Localidad;
import podologia.beansDB.Paciente;
import podologia.beansDB.Pais;
import podologia.beansDB.Persona;
import podologia.beansDB.Provincia;
import podologia.beansDB.Tipodoc;
import podologia.exceptions.BusinessException;
import podologia.util.ValidadorNumerico;

/**
 *
 * @author  Hernan
 */
public class NuevoPaciente extends javax.swing.JInternalFrame {

    //private Paciente paciente=new Paciente();
    //private List<Paciente> pacienteList=new ArrayList<Paciente>();
    // private Query pacienteQuery;
    private Paciente pacienteOpen;
    private int idPacienteOpen;
    private boolean update = false;

    /** Creates new form NuevoPaciente */
    public NuevoPaciente(int id) {
        idPacienteOpen = id;
        update = true;
        initComponents();
        editable(false);
    }

    //Constructor para Cagar los componente con un Paciente pasado como param.
    public NuevoPaciente(Paciente p) {
        pacienteOpen = p;
        update = true;
        initComponents();
        editable(false);
        cargar();
        this.setTitle("Editar Paciente " + p.getIdPersona().getApellido() + ", "+p.getIdPersona().getNombre());
    }

    public NuevoPaciente() {
        initComponents();
        editable(true);
        jButton2.setVisible(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(podologia.PodologiaApp.class).getContext().getResourceMap(NuevoPaciente.class);
        PodologiaPUEntityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory(resourceMap.getString("PodologiaPUEntityManager.persistenceUnit")).createEntityManager(); // NOI18N
        tipodocQuery = java.beans.Beans.isDesignTime() ? null : PodologiaPUEntityManager.createQuery("SELECT t FROM Tipodoc t");
        tipodocList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : tipodocQuery.getResultList();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jComboBoxTipoDoc = new javax.swing.JComboBox();
        jTextFieldApe = new javax.swing.JTextField();
        jTextFieldNom = new javax.swing.JTextField();
        jTextFieldTel = new javax.swing.JTextField();
        jTextFieldNroDoc = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldTelCelu = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jTextFieldFechaNac = new javax.swing.JTextField();
        jTextFieldNacionalidad = new javax.swing.JTextField();
        jTextFieldEstadocivil = new javax.swing.JTextField();
        jTextFieldDireCalle = new javax.swing.JTextField();
        jTextFieldDireBarrio = new javax.swing.JTextField();
        jTextFieldDireLoc = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jTextFieldDireNum = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jTextFieldDirePiso = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        jTextFieldDireDepto = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jTextFieldDireProvincia = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        jTextFieldDirePais = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jTextFieldGrupoSangui = new javax.swing.JTextField();
        jTextFieldOcupacion = new javax.swing.JTextField();
        jTextFieldDeporte = new javax.swing.JTextField();
        jTextFieldEmbarazo = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        jTextFieldObservaciones = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel1.setName("jPanel1"); // NOI18N

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jComboBoxTipoDoc.setName("jComboBoxTipoDoc"); // NOI18N

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, tipodocList, jComboBoxTipoDoc);
        bindingGroup.addBinding(jComboBoxBinding);

        jTextFieldApe.setText(resourceMap.getString("jTextFieldApe.text")); // NOI18N
        jTextFieldApe.setName("jTextFieldApe"); // NOI18N

        jTextFieldNom.setText(resourceMap.getString("jTextFieldNom.text")); // NOI18N
        jTextFieldNom.setName("jTextFieldNom"); // NOI18N

        jTextFieldTel.setText(resourceMap.getString("jTextFieldTel.text")); // NOI18N
        jTextFieldTel.setName("jTextFieldTel"); // NOI18N

        jTextFieldNroDoc.setText(resourceMap.getString("jTextFieldNroDoc.text")); // NOI18N
        jTextFieldNroDoc.setName("jTextFieldNroDoc"); // NOI18N

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jTextFieldTelCelu.setText(resourceMap.getString("jTextFieldTelCelu.text")); // NOI18N
        jTextFieldTelCelu.setName("jTextFieldTelCelu"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addContainerGap(620, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldApe, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                            .addComponent(jTextFieldNom, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jTextFieldTel, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel7))
                                    .addComponent(jComboBoxTipoDoc, javax.swing.GroupLayout.Alignment.TRAILING, 0, 176, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTextFieldTelCelu)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldNroDoc, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGap(247, 247, 247))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldApe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldNom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jComboBoxTipoDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldNroDoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldTelCelu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel2.setName("jPanel2"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        jTextFieldFechaNac.setText(resourceMap.getString("jTextFieldFechaNac.text")); // NOI18N
        jTextFieldFechaNac.setName("jTextFieldFechaNac"); // NOI18N

        jTextFieldNacionalidad.setText(resourceMap.getString("jTextFieldNacionalidad.text")); // NOI18N
        jTextFieldNacionalidad.setName("jTextFieldNacionalidad"); // NOI18N

        jTextFieldEstadocivil.setText(resourceMap.getString("jTextFieldEstadocivil.text")); // NOI18N
        jTextFieldEstadocivil.setName("jTextFieldEstadocivil"); // NOI18N

        jTextFieldDireCalle.setText(resourceMap.getString("jTextFieldDireCalle.text")); // NOI18N
        jTextFieldDireCalle.setName("jTextFieldDireCalle"); // NOI18N

        jTextFieldDireBarrio.setText(resourceMap.getString("jTextFieldDireBarrio.text")); // NOI18N
        jTextFieldDireBarrio.setName("jTextFieldDireBarrio"); // NOI18N

        jTextFieldDireLoc.setText(resourceMap.getString("jTextFieldDireLoc.text")); // NOI18N
        jTextFieldDireLoc.setName("jTextFieldDireLoc"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jTextFieldDireNum.setText(resourceMap.getString("jTextFieldDireNum.text")); // NOI18N
        jTextFieldDireNum.setName("jTextFieldDireNum"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        jTextFieldDirePiso.setText(resourceMap.getString("jTextFieldDirePiso.text")); // NOI18N
        jTextFieldDirePiso.setName("jTextFieldDirePiso"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        jTextFieldDireDepto.setText(resourceMap.getString("jTextFieldDireDepto.text")); // NOI18N
        jTextFieldDireDepto.setName("jTextFieldDireDepto"); // NOI18N

        jLabel19.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jTextFieldDireProvincia.setText(resourceMap.getString("jTextFieldDireProvincia.text")); // NOI18N
        jTextFieldDireProvincia.setName("jTextFieldDireProvincia"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        jTextFieldDirePais.setText(resourceMap.getString("jTextFieldDirePais.text")); // NOI18N
        jTextFieldDirePais.setName("jTextFieldDirePais"); // NOI18N

        jLabel21.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        jLabel22.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        jLabel23.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel23.setText(resourceMap.getString("jLabel23.text")); // NOI18N
        jLabel23.setName("jLabel23"); // NOI18N

        jLabel24.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel24.setText(resourceMap.getString("jLabel24.text")); // NOI18N
        jLabel24.setName("jLabel24"); // NOI18N

        jTextFieldGrupoSangui.setText(resourceMap.getString("jTextFieldGrupoSangui.text")); // NOI18N
        jTextFieldGrupoSangui.setName("jTextFieldGrupoSangui"); // NOI18N

        jTextFieldOcupacion.setText(resourceMap.getString("jTextFieldOcupacion.text")); // NOI18N
        jTextFieldOcupacion.setName("jTextFieldOcupacion"); // NOI18N

        jTextFieldDeporte.setText(resourceMap.getString("jTextFieldDeporte.text")); // NOI18N
        jTextFieldDeporte.setName("jTextFieldDeporte"); // NOI18N

        jTextFieldEmbarazo.setText(resourceMap.getString("jTextFieldEmbarazo.text")); // NOI18N
        jTextFieldEmbarazo.setName("jTextFieldEmbarazo"); // NOI18N

        jLabel25.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel25.setText(resourceMap.getString("jLabel25.text")); // NOI18N
        jLabel25.setName("jLabel25"); // NOI18N

        jTextFieldObservaciones.setText(resourceMap.getString("jTextFieldObservaciones.text")); // NOI18N
        jTextFieldObservaciones.setName("jTextFieldObservaciones"); // NOI18N

        jLabel26.setText(resourceMap.getString("jLabel26.text")); // NOI18N
        jLabel26.setName("jLabel26"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel8)
                    .addComponent(jLabel12)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldFechaNac, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                            .addComponent(jTextFieldNacionalidad)
                            .addComponent(jTextFieldEstadocivil))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel26))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDireBarrio))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDireCalle, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel21, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
                                    .addComponent(jLabel22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel25, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTextFieldDireProvincia)
                                    .addComponent(jTextFieldGrupoSangui, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                    .addComponent(jTextFieldOcupacion, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                    .addComponent(jTextFieldDeporte, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                    .addComponent(jTextFieldEmbarazo, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                                    .addComponent(jTextFieldObservaciones, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(jLabel16))
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel20)
                                .addComponent(jLabel15)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jTextFieldDirePais)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jTextFieldDireLoc))))
                .addGap(159, 159, 159))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel10, jLabel11, jLabel12, jLabel13, jLabel14, jLabel9});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldFechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel26))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldNacionalidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldEstadocivil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTextFieldDireCalle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldDireDepto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel18)
                    .addComponent(jTextFieldDirePiso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel16)
                    .addComponent(jTextFieldDireNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(jTextFieldDireBarrio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15)
                    .addComponent(jTextFieldDireLoc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel19)
                    .addComponent(jTextFieldDireProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20)
                    .addComponent(jTextFieldDirePais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(jTextFieldGrupoSangui, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(jTextFieldOcupacion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jTextFieldDeporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel24)
                    .addComponent(jTextFieldEmbarazo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(jTextFieldObservaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29))
        );

        jButton3.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton2.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setFont(resourceMap.getFont("jButton3.font")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 759, Short.MAX_VALUE)
                        .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(21, 21, 21))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2, jButton3});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-602)/2, 800, 602);
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    PodologiaPUEntityManager.close();
    dispose();
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    if (jButton2.getText().equals("Editar")) {
        editable(true);
        jButton2.setText("Cancelar");

    } else {
        if (jButton2.getText().equals("Cancelar")) {
            editable(false);
            cargar();
            jButton2.setText("Editar");

        }
    }

}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    try {
        validarDatos();
        if (update) {
            update();
        } else {
            guardar();
        }
    } catch (RuntimeException ex) {
        JOptionPane.showMessageDialog(this, ex.getMessage());
    }
}//GEN-LAST:event_jButton3ActionPerformed

    private void editable(boolean flag) {
        if (flag) {
            for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
                if (this.jPanel1.getComponent(i) instanceof JTextComponent && !this.jPanel1.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(true);
                }
            }
            for (int i = 0; i < this.jPanel2.getComponentCount(); i++) {
                if (this.jPanel2.getComponent(i) instanceof JTextComponent && !this.jPanel2.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel2.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel2.getComponent(i)).setEditable(true);
                }
            }
            
        } else {
            for (int i = 0; i < this.jPanel1.getComponentCount(); i++) {
                if (this.jPanel1.getComponent(i) instanceof JTextComponent && !this.jPanel1.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel1.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel1.getComponent(i)).setEditable(false);
                }
            }
            for (int i = 0; i < this.jPanel2.getComponentCount(); i++) {
                if (this.jPanel2.getComponent(i) instanceof JTextComponent && !this.jPanel2.getComponent(i).getClass().equals(jComboBoxTipoDoc.getClass()) && !this.jPanel2.getComponent(i).getClass().equals(jLabel1.getClass())) {
                    ((JTextComponent) this.jPanel2.getComponent(i)).setEditable(false);
                }
            }
        }
        
        jComboBoxTipoDoc.setEditable(flag);
        
    }

    private void guardar() {
        //Datos Persona
        Persona persona = new Persona();
        Paciente paciente = new Paciente();
        Direccion dire = new Direccion();
        Barrio barrio = new Barrio();
        Localidad loca = new Localidad();
        Provincia prov = new Provincia();
        Pais pais = new Pais();

        prov.setIdPais(pais);
        loca.setIdProvincia(prov);
        barrio.setIdLocalidad(loca);
        dire.setIdBarrio(barrio);
        persona.setIdDireccion(dire);
        paciente.setIdPersona(persona);

        paciente.getIdPersona().setApellido(jTextFieldApe.getText());
        paciente.getIdPersona().setNombre(jTextFieldNom.getText());


        paciente.getIdPersona().setIdTipoDoc((Tipodoc) jComboBoxTipoDoc.getSelectedItem());

        try {
            Double nroDoc = (Double) ValidadorNumerico.Validar(jTextFieldNroDoc, Double.class);
            paciente.getIdPersona().setNroDoc(nroDoc);
        } catch (NumberFormatException ex) {
            throw new BusinessException("El Documento debe contener solo numeros");
        }

        try{
            Integer TelPar = (Integer) ValidadorNumerico.Validar(jTextFieldTel, Integer.class);
            paciente.getIdPersona().setTelParticular(TelPar);
        }catch(NumberFormatException ex){
            throw new BusinessException("El Telefono Particular debe contener solo numeros");
        }

        try{
            Integer TelMov = (Integer) ValidadorNumerico.Validar(jTextFieldTelCelu, Integer.class);
            paciente.getIdPersona().setTelMovil(TelMov);
        }catch(NumberFormatException ex){
            throw new BusinessException("El Telefono Movil debe contener solo numeros");
        }

        paciente.getIdPersona().setFechaNacimiento(jTextFieldFechaNac.getText());
        paciente.getIdPersona().setNacionalidad(jTextFieldNacionalidad.getText());
        paciente.getIdPersona().setEstadoCivil(jTextFieldEstadocivil.getText());

        paciente.getIdPersona().getIdDireccion().setCalle(jTextFieldDireCalle.getText());
        paciente.getIdPersona().getIdDireccion().setNumero(jTextFieldDireNum.getText());
        paciente.getIdPersona().getIdDireccion().setPiso(jTextFieldDirePiso.getText());
        paciente.getIdPersona().getIdDireccion().setDepto(jTextFieldDireDepto.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().setNombre(jTextFieldDireBarrio.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().setNombre(jTextFieldDireLoc.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().setNombre(jTextFieldDireProvincia.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().setNombre(jTextFieldDirePais.getText());

        //Datos Paciente
        paciente.setGrupoSanquineo(jTextFieldGrupoSangui.getText());
        paciente.setOcupacion(jTextFieldOcupacion.getText());
        paciente.setDeporte(jTextFieldDeporte.getText());
        paciente.setEmbarazo(jTextFieldEmbarazo.getText());
        paciente.setDetalle(jTextFieldObservaciones.getText());

        //Persistencia del Objeto
        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        try {
            tx.begin();
            PodologiaPUEntityManager.persist(paciente);
            tx.commit();
            JOptionPane.showMessageDialog(this, "Paciente Guardado");
            dispose();
        } catch (RuntimeException ex) {
            tx.rollback();
            JOptionPane.showMessageDialog(this, "Error al guardar el paciente");
        }

    }

    private void update() {

        //Datos Persona
        Paciente paciente = pacienteOpen;

        paciente.getIdPersona().setApellido(jTextFieldApe.getText());
        paciente.getIdPersona().setNombre(jTextFieldNom.getText());
        paciente.getIdPersona().setIdTipoDoc((Tipodoc) jComboBoxTipoDoc.getSelectedItem());
        paciente.getIdPersona().setNroDoc(Double.parseDouble(jTextFieldNroDoc.getText()));
        paciente.getIdPersona().setTelParticular(Integer.parseInt(jTextFieldTel.getText()));
        paciente.getIdPersona().setTelMovil(Integer.parseInt(jTextFieldTelCelu.getText()));
        paciente.getIdPersona().setFechaNacimiento(jTextFieldFechaNac.getText());
        paciente.getIdPersona().setNacionalidad(jTextFieldNacionalidad.getText());
        paciente.getIdPersona().setEstadoCivil(jTextFieldEstadocivil.getText());
        paciente.getIdPersona().getIdDireccion().setCalle(jTextFieldDireCalle.getText());
        paciente.getIdPersona().getIdDireccion().setNumero(jTextFieldDireNum.getText());
        paciente.getIdPersona().getIdDireccion().setPiso(jTextFieldDirePiso.getText());
        paciente.getIdPersona().getIdDireccion().setDepto(jTextFieldDireDepto.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().setNombre(jTextFieldDireBarrio.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().setNombre(jTextFieldDireLoc.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().setNombre(jTextFieldDireProvincia.getText());
        paciente.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().setNombre(jTextFieldDirePais.getText());
        //Datos Paciente
        paciente.setGrupoSanquineo(jTextFieldGrupoSangui.getText());
        paciente.setOcupacion(jTextFieldOcupacion.getText());
        paciente.setDeporte(jTextFieldDeporte.getText());
        paciente.setEmbarazo(jTextFieldEmbarazo.getText());
        paciente.setDetalle(jTextFieldObservaciones.getText());

        //Persistencia del Objeto

        EntityTransaction tx = PodologiaPUEntityManager.getTransaction();
        tx.begin();
        PodologiaPUEntityManager.merge(paciente);
        tx.commit();


    }

    private void cargar() {

        //Datos Persona
        DecimalFormat df = new DecimalFormat("0");
        jTextFieldApe.setText(pacienteOpen.getIdPersona().getApellido());
        jTextFieldNom.setText(pacienteOpen.getIdPersona().getNombre());
        jComboBoxTipoDoc.setSelectedItem(pacienteOpen.getIdPersona().getIdTipoDoc().getIdTipo());
        jTextFieldNroDoc.setText(df.format(pacienteOpen.getIdPersona().getNroDoc()));
        jTextFieldTel.setText(pacienteOpen.getIdPersona().getTelParticular().toString());
        jTextFieldTelCelu.setText(pacienteOpen.getIdPersona().getTelMovil().toString());
        jTextFieldFechaNac.setText(pacienteOpen.getIdPersona().getFechaNacimiento());
        jTextFieldNacionalidad.setText(pacienteOpen.getIdPersona().getNacionalidad());
        jTextFieldEstadocivil.setText(pacienteOpen.getIdPersona().getEstadoCivil());
        jTextFieldDireCalle.setText(pacienteOpen.getIdPersona().getIdDireccion().getCalle());
        jTextFieldDireNum.setText(pacienteOpen.getIdPersona().getIdDireccion().getNumero());
        jTextFieldDirePiso.setText(pacienteOpen.getIdPersona().getIdDireccion().getPiso());
        jTextFieldDireDepto.setText(pacienteOpen.getIdPersona().getIdDireccion().getDepto());
        jTextFieldDireBarrio.setText(pacienteOpen.getIdPersona().getIdDireccion().getIdBarrio().getNombre());
        jTextFieldDireLoc.setText(pacienteOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getNombre());
        jTextFieldDireProvincia.setText(pacienteOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getNombre());
        jTextFieldDirePais.setText(pacienteOpen.getIdPersona().getIdDireccion().getIdBarrio().getIdLocalidad().getIdProvincia().getIdPais().getNombre());
        //Datos Paciente
        jTextFieldGrupoSangui.setText(pacienteOpen.getGrupoSanquineo());
        jTextFieldOcupacion.setText(pacienteOpen.getOcupacion());
        jTextFieldDeporte.setText(pacienteOpen.getDeporte());
        jTextFieldEmbarazo.setText(pacienteOpen.getEmbarazo());
        jTextFieldObservaciones.setText(pacienteOpen.getDetalle());

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.persistence.EntityManager PodologiaPUEntityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBoxTipoDoc;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextFieldApe;
    private javax.swing.JTextField jTextFieldDeporte;
    private javax.swing.JTextField jTextFieldDireBarrio;
    private javax.swing.JTextField jTextFieldDireCalle;
    private javax.swing.JTextField jTextFieldDireDepto;
    private javax.swing.JTextField jTextFieldDireLoc;
    private javax.swing.JTextField jTextFieldDireNum;
    private javax.swing.JTextField jTextFieldDirePais;
    private javax.swing.JTextField jTextFieldDirePiso;
    private javax.swing.JTextField jTextFieldDireProvincia;
    private javax.swing.JTextField jTextFieldEmbarazo;
    private javax.swing.JTextField jTextFieldEstadocivil;
    private javax.swing.JTextField jTextFieldFechaNac;
    private javax.swing.JTextField jTextFieldGrupoSangui;
    private javax.swing.JTextField jTextFieldNacionalidad;
    private javax.swing.JTextField jTextFieldNom;
    private javax.swing.JTextField jTextFieldNroDoc;
    private javax.swing.JTextField jTextFieldObservaciones;
    private javax.swing.JTextField jTextFieldOcupacion;
    private javax.swing.JTextField jTextFieldTel;
    private javax.swing.JTextField jTextFieldTelCelu;
    private java.util.List<podologia.beansDB.Tipodoc> tipodocList;
    private javax.persistence.Query tipodocQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    private void validarDatos() throws BusinessException {
        StringBuilder error = new StringBuilder();
        Boolean hayError = false;

        if (jTextFieldApe.getText().isEmpty()) {
            jTextFieldApe.setBackground(Color.RED);
            hayError = true;
            error.append("El Apellido no puede estar vacio \n");
        } else {
            jTextFieldApe.setBackground(Color.WHITE);
        }
        if (jTextFieldNom.getText().isEmpty()) {
            jTextFieldNom.setBackground(Color.RED);
            hayError = true;
            error.append("El Nombre no puede estar vacio \n");
        } else {
            jTextFieldNom.setBackground(Color.WHITE);
        }
        if (jTextFieldNroDoc.getText().isEmpty()) {
            jTextFieldNroDoc.setBackground(Color.RED);
            hayError = true;
            error.append("El Numero de Documento no puede estar vacio \n");
        } else {
            jTextFieldNroDoc.setBackground(Color.WHITE);
        }

        if (hayError) {
            throw new BusinessException(error.toString());
        }


    }

    
}
